package api

import (
	"fmt"

	"gitee.com/ruige_fun/util/rlog"
	"github.com/go-playground/validator/v10"
	"github.com/iris-contrib/schema"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/middleware/recover"
)

func init() {
	//表单，URL参数，请求头参数，请求路径参数，添加额外的tag支持
	schema.Form.AddAliasTag("json")
	schema.Query.AddAliasTag("json")
	schema.Headers.AddAliasTag("json")
	schema.Params.AddAliasTag("json")
}

func Run(port uint) {
	app := iris.New()
	app.Validator = validator.New()
	app.Use(recover.New())
	router(app)
	err := app.Run(iris.Addr(fmt.Sprint(":", port)), iris.WithPostMaxMemory(512*iris.MB), iris.WithRemoteAddrHeader("X-Real-IP", "X-Forwarded-For"))
	if err != nil {
		rlog.Panic("启动服务失败(http)：", err)
	}
}
